
#include <list>
#include <time.h>
#include <cstdlib>
#include <iostream>


#include "Heap.h"
#include "Comparable.h"
#include "Tree.h"
#include "AvlTree.h"
#include "HeapSort.h"

int main(int argc, char* argv[]) {
    /* initialize random seed: */
    srand ( time(NULL) );

    /* heap test with heap sort */
    Heap<int, 10> heapIntSize10;
    int arrayToSort[10];
    for (int i = 0; i <  10; ++i) {   
        heapIntSize10.push(i);
        arrayToSort[i] = rand() % 10;
    }
    std::cout << "printing heap<int, 10: \n";
    heapIntSize10.print();
    std::cout << "#############################################" << std::endl;
    
    Comparable test1(1,1);
    Comparable test2(2,2);
    Comparable test3(3,3);
    Heap<Comparable, 2> heapComparableSize2;
    heapComparableSize2.push(test1);
    heapComparableSize2.push(test2);
    std::cout << "printing heap<Comparable, 2: \n";
    heapComparableSize2.print();
    std::cout << "#############################################" << std::endl;

    //std::cout << "triing to add a third Comparable should ASSERT!\n";
    //heapComparableSize2.push(test3);
    
    std::cout << "printing heap<int>sorted using heap_sort algorithm: \n";
    HeapSort<int,10>::sort(arrayToSort);
    for (int i = 0; i < 10; ++i) {
        std::cout << arrayToSort[i] << " ";
    }
    std::cout << std::endl;
    std::cout << "#############################################" << std::endl;

    std::list<int> listInt;
    listInt = heapIntSize10.toSortedList();

    std::cout << "printing heap<int>sorted using heap: \n";
    for (std::list<int>::iterator it = listInt.begin(); it != listInt.end(); ++it) {
        std::cout << *it << " ";
    }
    std::cout << std::endl;
    std::cout << "#############################################" << std::endl;

    std::list<Comparable> listComparable;
    listComparable = heapComparableSize2.toSortedList();
    std::cout << "printing heap<Comparable>sorted using heap: \n";
    for (std::list<Comparable>::iterator it = listComparable.begin(); it != listComparable.end(); ++it) {
        std::cout << *it << " ";
    }
    std::cout << std::endl;
    std::cout << "#############################################" << std::endl;
    
    Tree testTree;
    AvlTree testAvlTree;
   
    for (int i = 0; i < 5; ++i) {
        std::cout << "filling tree/avltree with: " << i * 10000 << std::endl;
        for (int j = 0; j < 10000; ++j) {
            testTree.insert((double)rand());
            testAvlTree.insert((double)rand());
        }
        std::cout << "tree-height: " << testTree.height() << std::endl;
        std::cout << "avl-tree-height: " << testAvlTree.height() << std::endl;
    }
    std::cout << "#############################################" << std::endl;

    return 0;
}